/*
 * RTSAI - Real-Time Strategy engine for AI research
 * Copyright(C) 2006 DIMAp-UFRN, licensed under LGPL
 *
 * Simple C++ log library
 * Lib initially based on .h by August Schwerdfeger
 * (http://www.tc.umn.edu/~schw0709/programs/log_libraries.html)
 */

#ifndef __LOG_CPP_
#define __LOG_CPP_

#include "Log.h"

/*! Creates a logger instance when the method is called for the first time.
 *  It is the "construct on first use" idiom for avoiding prior static
 *  initializations problems.
 */
Logger& Logger :: logger()
{
    static Logger logger;
    return logger;
}

/*! Default constructor.
 */
Logger::Logger() {
    stream = &(std::cout);  // default: standart output
    logLevel = ALLWAYS;
    msgLevel = ALLWAYS;
}


/*! Returns the actual Log Level
 */
Logger::LogLevel Logger::get_level()
{
    return logger().logLevel;
}


/*! Sets actual log level as parameters
 *  @param newLevel New log level
 */
void Logger::set_level ( LogLevel newLevel )
{
  if ( newLevel >= 0 && newLevel <= NONE)
    logger().logLevel = newLevel;
}


/*! Logs to a specified stream, log level specified
 *  @param newStream New output
 */
void Logger::set_output ( std::ostream& newStream )
{
  logger().stream = &newStream;
}


Logger& Logger::get_logger ( LogLevel newMsgLevel )
{
    if(newMsgLevel >= 0 && newMsgLevel < NONE)
    {
        logger().msgLevel = newMsgLevel;
    }
    return logger();
}

#endif // endif __LOG_CPP_
